TEGL WINDOWS The high-level windows in the TEGL WINDOWS TOOLKIT provide a consistent graphical interface for your application. Many routines are provided that are associated with a window or are window relative. A number of devices are provided that would require a fair bit of coding using the lower levels of the toolkit. * Header * Local menus * Minimize & Maximise buttons * Resizers * Sliders * Dialog management * World Coordinates A drawback to the high-level windows is the necessity of coding a redraw event for windows that are resizeable. Here is a simple window: BEGINFILE> twwin1.c /* -- twwin1.c */ #include "teglsys.h" winframeptr wf; void main(void) { tweasystart(); twinit(&wf,100,50,300,150); twsetheader(wf,"A Simple Window"); twdrawwindowframe(wf); teglsupervisor(); } ENDFILE> When you compile and run this program you'll get a window with a header and resize areas. Lets examine what each step in this programs does. The first call to tweasystart does the graphics system and window manager initialization including autodetection of the graphics hardware and clearing the screen. Additionally it places an exit button in the lower right corner of the screen so you can always exit your program. twinit creates a window frame (the first parameter wf is a winframeptr) memory block, the numbers indicate the screen area that the window should occupy (x1, y1, x2, y2). twinit must always be called before an other routines that have a winframeptr as their first argument. twsetheader says this window will have a header displayed (default is no header) and what is displayed in it. twdrawwindowframe actually draws the window on the screen. This is always called after all the conditions for a window have been set. teglsupervisor is the event-supervisor. It will poll for events (key-presses and mouse clicks) and call up the appropriate event-handler as required. The high-level windows have a number of pre-defined event-handlers that are automatically installed. There is the resizing events which look after the borders of the window so that a mouse click can stretch or shrink the window. Also there is the minimize and maximize buttons. The minimize button will shrink a window to an icon while the maximize button expands it to fill the entire screen. CONTROL FUNCTIONS winframeptr findwinframe(imagestkptr frame);frame : ImageStkPtr); This function is used to locate a winframeptr that is associated with a frame (imagestkptr). It is called on entry to an event-handler to determine what window invoked it. void twselect(winframeptr wf); This function will select the window. This should be called on entry to any event-handler that uses a window, it does internal checks and sets the viewport to the working area. GLOBAL WINDOW SETUP twsetglobalbuttonsize(char width, char height); Set the size of the buttons on the window. Generally if the defaults are not satisfactory then this can be changed but should be done at start up before any windows are drawn. This affects all windows. twsetglobalslidersize(char updown, char leftright); Sets the size of the slider thumb (the button that slides). This only affects on dimension of the slider thumbs, the other is set to conform to the button sizes. twsetglobresizearea(char width, char height); Sets the size of the resize corner areas of the window border. Width is the x distance (in pixels) and Height is the y distance. The thickness of the border is used to complete the resize areas, this defaults to 4 pixels and can be changed on individual windows. twsetheaderfont(fontptr font); Sets the font that all subsequent windows will use for headers and menus. This example sets these global items to illustrate how the window style is affected. The best use of these items is to control the window look on different video displays and would best be set at the start of a program and left alone during the run. BEGINFILE> twwin2.c /* -- twwin2.c */ #include "teglsys.h" winframeptr wf; void main(void) { tweasystart(); twsetglobalbuttonsize(24,12); twsetglobalslidersize(36,8); twsetglobalresizearea(50,20); twsetheaderfont(&f8x12bol); twinit(&wf,100,50,300,170); twsetheader(wf,"Common Window characteristics"); twsetwindowstyle(wf,stdbox); twsetupdownslider(wf,TRUE); twsetleftrightslider(wf,TRUE); twdrawwindowframe(wf); teglsupervisor(); } ENDFILE> WINDOW FEATURES The following functions set features on a window that affect only that window. Note that each one requires a winframeptr at the first argument. twsetbordercolor(winframeptr wf, char color); Sets the color of the window border. The border is the one pixel outline. twsetcloseevent(winframeptr wf, callproc closeevent); Sets the event to call when a window is disposed of. The closeevent does not have to be set (a default one is in place). twsetdisplayfont(winframeptr, fontptr font); Sets the font to use with the window. This affects the header and menus. twsetmaximize(winframeptr wf, unsigned char tf); Sets whether a window is minimize/maximizeable. If TRUE then the window will have the minimize/maximize buttons. Only has an effect on windows with a header. twsetredraw(winframeptr wf, callproc redraw); Sets the redrawing function for a window. The redrawing function is an event-handler. This function is called after the kernel draws the window (border, buttons, menu etc.) when first created and any time the window must be redraw, like after it has been re-sized. twsetheader(winframeptr wf, char *s); Sets the window header to s. Window header must be set to enable the minimize/maximize buttons. twsetthickness(winframeptr wf, char thickness); Sets the thickness of the window border. Thickness cannot be less than one. The thickness affects the size of the resize areas (if resizing is enabled for the window). twsetwinframecolor(winframeptr wf, char color1, char color2); Sets the colors to use on the upper left and lower right of the window. twsetwindowstyle(winframeptr wf, framedrawfunc style); Sets the drawing function to draw the border of the window frame. Currently there are two drawing functions, stdbox and bevbox. ------------------------------------------------------------------ This example uses many of window features, you don't need to set them all, the defaults are usually fine, but by changing them around you can see the effects. BEGINFILE> twwin3.c /* -- twwin3.c */ #include "teglsys.h" winframeptr wf; /* -- RedrawIt is a standard event-handler. It is called after */ /* -- the window standard items have been drawn. */ unsigned redrawit(imagestkptr ifs, msclickptr ms) { winframeptr wf; wf = findwinframe(ifs); twputpict(wf,1,1,imageSYSTEM,BLACK); return 0; } /* -- this is the close event for the window. */ unsigned closeit(imagestkptr ifs, msclickptr ms) { winframeptr wf; int i; int color; wf = findwinframe(ifs); prepareforupdate(ifs); /* -- prove that we are going through here */ color = 0; for (i = 0; i <= 100; i++) { twsetfillcolor(wf,color); twclear(wf); color++; if (color > 15) color = 0; } commitupdate(); /* -- then call close to actually dispose of the window */ twclose(wf); return 0; } void main(void) { tweasystart(); twinit(&wf,100,50,300,170); twsetheader(wf,"Window characteristics"); twsetthickness(wf,6); twsetfillcolor(wf,GREEN); twsetbordercolor(wf,BLACK); twsetwinframecolors(wf,CYAN,MAGENTA); twsetmaximize(wf,FALSE); /* -- no minimize/maximize */ twsetwindowstyle(wf,bevbox); twsetredraw(wf,redrawit); twsetcloseevent(wf,closeit); twdrawwindowframe(wf); teglsupervisor(); } ENDFILE> WINDOW FUNCTIONS twclear(winframeptr wf); Clears the window to the color set by twsetfillcolor. twscrolldown(winframeptr wf, int num); twscrollup(winframetpr wf, int num); These functions will scroll the working area of the window up or down by Num pixels. The area cleared is filled using the current fillcolor set by twsetfillcolor. Sliders - twsetupdownslider(winframeptr wf, unsigned char active); twsetleftrightslider(winframeptr wf, unsigned char active); These enable (or disable) the sliders from being attacted to a window. TRUE turns sliders on, FALSE turns them off. If the slider is changed after the window is displayed then it must be redrawn for it to take effect. Sliders won't be displayed if a window becomes too small. twsetleftrightevent(winframeptr, callproc event); twsetupdownevent(winframeptr wf, callproc event); These set the event to be called after a slider has been moved. This means either the slider thumb or the end point buttons. twsetleftrightrange(winframeptr wf, int range, int step); twsetupdownrange(winframeptr wf, int range, int step); The slider movement can be gauged by setting its range (from 0 to range) and the step. Range is an arbitrary value that would reflect the item that the slider is used to scroll. Step is the increment value to use with the end point buttons. Menus - Two functions provide for a straight forward local menu facility. On both the string parameter is the displayed menu selection. Active is to set whether the menu item is to be active (clickable). If a menu item is passed with tildes '~' around a character then that item is displayed with an underscore and the appropriate keypress is trapped (if the window is active). twmenuitem(winframeptr wf, char *s, unsigned char active); Add a local bar menu item to the window. After adding a bar menu item the sub menu items must be delared immediately afterward using twSubMenuItem. twsubmenuitem(winframeptr wf, char *s, unsigned char active, callproc event); Add a submenu item to the local bar menu item most recently added. Event is the event-handler to call when the sub menu item is selected. An important consideration with windows that have local menus is the imagestkptr that is passed to the event-handler. It is not the imagestkptr of the Window but of the smaller frame that the menu is displayed in. This is consistent in that an event-handler is always passed the frame that the mouse click originated on. To determine what window this event-handler is being called from use the related stack as in ifs^.related stack. BEGINFILE> twwin4.c /* -- twwin4.c */ #include "teglsys.h" winframeptr wf; /* -- RedrawIt is a standard event-handler. It is called after */ /* -- the window standard items have been drawn. */ unsigned redrawit(imagestkptr ifs, msclickptr ms) { winframeptr wf; wf = findwinframe(ifs); twputpict(wf,10,10,&imageSYSTEM,BLACK); return 0; } /* -- this is the close event for the window. */ unsigned closeit(imagestkptr ifs, msclickptr ms) { winframeptr wf; int i; int color; wf = findwinframe(ifs); prepareforupdate(ifs); /* -- prove that we are going through here */ color = 0; for (i = 0; i <= 100; i++) { twsetfillcolor(wf,color); twclear(wf); color++; if (color > 15) color = 0; } commitupdate(); /* -- then call close to actually dispose of the window */ twclose(wf); return 0; } /* -- this event-handler just chains to CloseIt, the important */ /* -- notation here is the use of the related stack for local */ /* -- menu selections to determine the correct WinFramePtr */ unsigned menucloseit(imagestkptr ifs, msclickptr ms) { return closeit(ifs->relatedstack,ms); } void main(void) { tweasystart(); twinit(&wf,100,50,300,190); twsetheader(wf,"Window with a local menu"); twsetmaximize(wf,FALSE); /* -- no minimize/maximize */ twsetredraw(wf,redrawit); twsetcloseevent(wf,closeit); twmenuitem(wf,"~F~ile",TRUE); /* -- NilUnitProc is just a dummy event-handler, use it */ /* -- as a place holder when you are just building an interface */ twsubmenuitem(wf,"~O~pen",TRUE,nilunitproc); twsubmenuitem(wf,"-",FALSE,nilunitproc); twsubmenuitem(wf,"E~x~it",TRUE,menucloseit); twmenuitem(wf,"~D~raw",TRUE); twsubmenuitem(wf,"~A~rc",FALSE,nilunitproc); twsubmenuitem(wf,"~C~ircle",FALSE,nilunitproc); twsubmenuitem(wf,"~E~llipse",FALSE,nilunitproc); twsubmenuitem(wf,"~R~ectangle",FALSE,nilunitproc); twdrawwindowframe(wf); teglsupervisor(); } ENDFILE> Any of the example programs that start with a 'TW' are examples of the high-level window interface. ------------------------------------------------------------------- END TWQUICK.TXT